<?php
/**
 * licenses : MIT
 * creatTime: 2020/5/15
 * author : weblinuxgame
 * filename: ValidationHandler.php
 */

namespace App\Exceptions\Api;


use Throwable;
use App\Core\Traits\Api\ApiResponse;
use Illuminate\Validation\ValidationException;

/**
 * Class ValidationHandler
 * @package App\Exceptions\Api
 */
class ValidationHandler
{
    use ApiResponse;

    /**
     * 是否验证失败异常
     * @param Throwable $e
     * @return bool
     */
    public static function IsValidationException(Throwable $e): bool
    {
        if ($e instanceof ValidationException) {
            return true;
        }
        return false;
    }

    /**
     * 响应除了
     * @param $request
     * @param ValidationException $exception
     * @return mixed
     */
    public function render($request, Throwable $exception)
    {
        return $this->failed($exception->getMessage());
    }

}
